<template>
  <view class="content">
    <view class="title">
      <text>子组件B</text>
    </view>
    <view class="b-box">
      <text>ComA组件传进来的值：</text>
      <text class="intent-text-box">{{ result }}</text>
    </view>
    <view class="b-box" style="margin: 10rpx;">
      <text>回传值：</text>
      <input type="text" v-model="callbackValue" style="color: yellow; border: 1px solid #ccc; padding: 5rpx;" />
      <button @click="sendOutside()" size="mini">回传</button>
    </view>
  </view>
</template>

<script>
export default {
  name: "comB",
  data() {
    return {
      result: '',
      callbackValue: ''  // 初始化回传输入框变量
    }
  },
  methods: {
    sendOutside() {
      this.$emit('callBackFun', this.callbackValue);  // 确保事件名称与父组件一致
    }
  },
  created() {
    uni.$on('getIntent', (msg) => {
      this.result = msg;
    })
  }
}
</script>